package com.fyt.controller.utils;


import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//@RestControllerAdvice //异常处理类 需要让Mvc配置类扫描到
public class ProjectExceptionAdvice {

    @ExceptionHandler(Exception.class) //处理所有类型异常
//    @ExceptionHandler(MethodArgumentNotValidException.class) //处理参数不匹配发出的异常
    @ResponseBody
    public Result doException(Exception ex){
        System.out.println("捕获异常");
        return new Result(null,900,ex.getMessage());
    }
}
